const mysql = require('mysql2/promise')

const dbConfig = {
  host: 'localhost',
  user: 'root',
  password: 'GKL9512357',
  database: 'novel_platform',
  charset: 'utf8mb4'
}

async function checkTables () {
  let connection
  try {
    connection = await mysql.createConnection(dbConfig)

    console.log('📚 user_bookshelf 表结构:')
    const [bookshelfFields] = await connection.execute(
      'DESCRIBE user_bookshelf'
    )
    bookshelfFields.forEach(field => {
      console.log(
        `  ${field.Field}: ${field.Type} ${
          field.Null === 'YES' ? 'NULL' : 'NOT NULL'
        }`
      )
    })

    console.log('\n📖 reading_history 表结构:')
    const [historyFields] = await connection.execute('DESCRIBE reading_history')
    historyFields.forEach(field => {
      console.log(
        `  ${field.Field}: ${field.Type} ${
          field.Null === 'YES' ? 'NULL' : 'NOT NULL'
        }`
      )
    })

    // 检查现有数据
    const [bookshelfCount] = await connection.execute(
      'SELECT COUNT(*) as count FROM user_bookshelf'
    )
    const [historyCount] = await connection.execute(
      'SELECT COUNT(*) as count FROM reading_history'
    )

    console.log(`\n📊 数据统计:`)
    console.log(`  书架记录: ${bookshelfCount[0].count}`)
    console.log(`  阅读历史: ${historyCount[0].count}`)
  } catch (error) {
    console.error('❌ 错误:', error.message)
  } finally {
    if (connection) await connection.end()
  }
}

checkTables()
